Skip to content

[codex] split CLI entrypoint implementation - #375

Merged
delete-cloud merged 1 commit into
mainfrom
refactor/coding-agent-structure
May 24, 2026
Merged

delete-cloud merged 1 commit into
mainfrom
refactor/coding-agent-structure

Conversation

@delete-cloud

@delete-cloud delete-cloud commented May 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Move the Click CLI implementation from coding_agent.__main__ into coding_agent.cli.main.
  • Keep python -m coding_agent as a thin executable shim.
  • Preserve coding_agent.__main__ import/monkeypatch compatibility by aliasing imports to the CLI implementation module.
  • Add ADR-0048 and a task packet for the staged structure refactor.

Validation

  • uv run pytest tests/cli/ -v
  • uv run pytest tests/coding_agent/test_bootstrap.py -v
  • uv run pytest tests/coding_agent/test_cli_pipeline.py -v
  • uv run python -m coding_agent run --help
  • git diff --check

Summary by CodeRabbit

Release Notes

  • Refactor

    • Reorganized CLI command structure for improved maintainability while preserving all existing functionality.
  • Chores

    • Added architectural decision record documenting application structure refactor strategy.
    • Added implementation plan for CLI reorganization.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: daba0209-4e57-4224-b587-f55a4ec857d0

📥 Commits

Reviewing files that changed from the base of the PR and between 82d1ff0 and 12f39d1.

📒 Files selected for processing (4)
  • coding-agent/.opencode/prompts/tasks/coding-agent-structure-cli-entrypoint.md
  • coding-agent/docs/adr/0048-application-structure-refactor-boundaries.md
  • coding-agent/src/coding_agent/__main__.py
  • coding-agent/src/coding_agent/cli/main.py

📝 Walkthrough

Walkthrough

This PR reorganizes the CLI structure by extracting all Click command implementations from an oversized __main__.py into a focused cli/main.py module. The entry point becomes a minimal shim that delegates to the new CLI module, reducing __main__.py from 1,600+ lines to 18 lines while preserving all existing command signatures, behavior, and backward-compatible re-exports.

Changes

CLI Module Refactoring

Layer / File(s) Summary
Planning & Architecture Documentation
.opencode/prompts/tasks/coding-agent-structure-cli-entrypoint.md, docs/adr/0048-application-structure-refactor-boundaries.md
OpenCode task prompt and ADR-0048 document the planned CLI extraction refactor, specifying scope, first-slice approach, future moves, and acceptance criteria.
Entry Point Module Shim
src/coding_agent/__main__.py
__main__.py is reduced to an executable shim that imports coding_agent.cli.main, re-exports via sys.modules[__name__] for test patching, and delegates execution.
CLI Module Foundation & Shared Utilities
src/coding_agent/cli/main.py (lines 1–169)
Sets up the CLI module with backward-compatible re-exports (create_agent, create_child_pipeline) and implements shared Click option helpers and config merging.
Core Interactive & Operational Commands
src/coding_agent/cli/main.py (lines 171–484)
Implements run and repl batch/interactive commands, knowledge-base group (kb index, kb search), async execution helpers, and operational commands (stats, serve) with configuration loading.
Remote Server Endpoint Management & Core Execution
src/coding_agent/cli/main.py (lines 485–818)
Implements remote endpoint management (add, list, remove) and core execution flow (remote repl, _remote_run_once) with workspace source preparation, session streaming, and conditional cleanup.
Remote Execution Helpers & Formatting
src/coding_agent/cli/main.py (lines 820–1022)
Provides Git workspace source preparation, subprocess execution, and next-step CLI command generation for remote runs.
Remote Sessions & Workspaces Inspection
src/coding_agent/cli/main.py (lines 1024–1261)
Adds remote sessions and remote workspaces groups for inspection and control with list, status, cancel, close, retain, pin, unpin, cleanup, and rm subcommands.
Remote Result Inspection & Download
src/coding_agent/cli/main.py (lines 1263–1636)
Implements result output commands (result, diff, patch, publish), remote download with manifest parsing, attach for existing sessions, and verify for task contract validation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • delete-cloud/Coding-Agent-Loop#116: Previous PR added remote and attach commands in coding_agent.__main__, while this PR moves and reorganizes those same remote command implementations into the new cli/main.py module.

Poem

🐰 Hoppy refactor time!
CLI commands once dense and wide,
Now neatly organized inside—
A shim, a module, code compile!
Clean structure, all the while. ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/coding-agent-structure

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@delete-cloud
delete-cloud marked this pull request as ready for review May 24, 2026 16:49
@delete-cloud
delete-cloud merged commit d70079f into main May 24, 2026
1 check was pending
@delete-cloud
delete-cloud deleted the refactor/coding-agent-structure branch May 24, 2026 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant